// stores/counter.js
import { defineStore } from 'pinia'

export const useStore = defineStore('counter', {
    state: () => {
        return {
            count: 1,
            name: 'Eduardo',
            isAdmin: true,
            items: [],
            hasChanged: true,
        }
    },
    getters: {
        // 自动推断出返回类型是一个 number
        doubleCount(state) {
            return state.count * 2
        }
    },
    // 也可以这样定义
    // state: () => ({ count: 0 })
    actions: {
        increment() {
            this.count++
        },
        randomizeCounter() {
            this.count = Math.round(100 * Math.random())
        },
    },
})